<?php 
/**
 * Класс, который реализовует базовые методы менеджемна даних в таблице
 *
 */

class FRM_View_Ext_Form extends FRM_View_Ext_Abstract
{
	protected $formClassPrefix = 'FRM_View_Ext_Form_Template_';
	
	/**
	 * Enter description here...
	 *
	 * @var array
	 */
	protected $baseClass = "x-plain";

	/**
	 * Enter description here...
	 *
	 * @var string
	 */
	protected $labelWidth = 110;

	/**
	 * Enter description here...
	 *
	 * @var string
	 */
	protected $labelAlign  = 'left';

	/**
	 * Enter description here...
	 *
	 * @var boolean
	 */
	protected $border = 'false';

	/**
	 * Enter description here...
	 *
	 * @var string
	 */
	protected $buttonAlign = 'right';


	/**
	 * Enter description here...
	 *
	 * @param int $labelWidth
	 */
	public function setLabelWidth($labelWidth){
		$this->labelWidth = $labelWidth;
		return $this;
	}

	/**
	 * Enter description here...
	 *
	 * @param string $labelAlign
	 */
	public function setLabelAlign($labelAlign){
		$this->labelAlign = $labelAlign;
		return $this;
	}

	/**
	 * Enter description here...
	 *
	 * @param string $buttonAlign
	 */
	public function setButtonAlign($buttonAlign){
		$this->buttonAlign = $buttonAlign;
		return $this;
	}

	/**
	 * Enter description here...
	 *
	 * @param boolean $border
	 */
	public function setBorder($border){
		$this->border = $border;
		return $this;
	}

	public function render($formTemplate){
		$config = array('labelWidth'=>$this->labelWidth, 'autoHeight'=>$this->autoHeight, 'labelAlign'=>$this->labelAlign, 'border'=>$this->border, 'buttonAlign'=>$this->buttonAlign);
		
		$formTemplate = $this->formClassPrefix.$formTemplate;
		
		if(class_exists($formTemplate)){

			$form = new $formTemplate($this->varName, self::$langs, $config);
			//$form
			FRM_View_Ext_Form_Template_Abstract::setController(self::$controller);
			//print_r($this->items);
						
			foreach ($this->items as $item){
				$form->addField($item);
			}

			return $form->render();
		}
		return null;

	}

	public function __construct()
	{
		$this->autoHeight = true;
		$this->layout = new PhpExt_Layout_FitLayout();
	}
}